package com.todo.member.infrastructure.repository.impl;

import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.utils.StringUtils;
import com.todo.member.common.enums.MemberVipStatusEnum;
import com.todo.member.infrastructure.convert.MemberBaseConvert;
import com.todo.member.infrastructure.entity.condition.MemberVipInfoCondition;
import com.todo.member.infrastructure.entity.po.MemberVipInfoPO;
import com.todo.member.infrastructure.mapper.MemberVipInfoMapper;
import com.todo.member.infrastructure.repository.MemberVipInfoRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/2/10 11:53
 * @description
 */
@Repository
public class MemberVipInfoRepositoryImpl implements MemberVipInfoRepository {

    @Resource
    private MemberVipInfoMapper memberVipInfoMapper;

    @Override
    public Boolean insertMemberVipInfoPO(MemberVipInfoPO memberVipInfoPO) {
        if (memberVipInfoPO == null) {
            return false;
        }
        if (memberVipInfoPO.getVipCode() == null || memberVipInfoPO.getName() == null || memberVipInfoPO.getSellPrice() == null) {
            return null;
        }
        return memberVipInfoMapper.insertMemberVipInfoPO(memberVipInfoPO);
    }

    @Override
    public Boolean updateMemberVipInfoPOById(MemberVipInfoPO memberVipInfoPO) {
        if (memberVipInfoPO == null || memberVipInfoPO.getId() == null) {
            return false;
        }
        if (memberVipInfoPO.getVipCode() == null || memberVipInfoPO.getName() == null || memberVipInfoPO.getSellPrice() == null) {
            return null;
        }

        MemberVipInfoPO operateData = MemberBaseConvert.buildUpdateMemberVipInfoPO(memberVipInfoPO);
        return memberVipInfoMapper.insertMemberVipInfoPO(operateData);
    }

    @Override
    public Boolean removeMemberVipInfoPOById(Long id) {
        if (id == null || id < 0) {
            return false;
        }
        return memberVipInfoMapper.removeMemberVipInfoPOById(id);
    }

    @Override
    public MemberVipInfoPO queryMemberVipInfoPOById(Long id) {
        if (id == null || id < 0) {
            return null;
        }
        return memberVipInfoMapper.queryMemberVipInfoPOById(id);
    }


    @Override
    public MemberVipInfoPO queryMemberVipInfoPOByName(String name) {
        if (StringUtils.isBlank(name)) {
            return null;
        }
        return memberVipInfoMapper.queryMemberVipInfoPOByName(name);
    }

    @Override
    public Boolean updateMemberVipInfoStatusById(Long id, MemberVipStatusEnum oldStatus, MemberVipStatusEnum newStatus) {
        if (id == null || id < 0 || oldStatus == null || newStatus == null) {
            return false;
        }
        return memberVipInfoMapper.updateMemberVipInfoStatusById(id, oldStatus.getType(), newStatus.getType());
    }

    @Override
    public PageResult<MemberVipInfoPO> queryMemberVipInfoPOByPage(MemberVipInfoCondition memberVipInfoCondition) {
        return null;
    }

    @Override
    public MemberVipInfoPO queryMemberVipInfoByVipCode(String vipCode, Integer version) {
        return memberVipInfoMapper.queryMemberVipInfoByVipCode(vipCode, version);
    }

    public List<MemberVipInfoPO> queryMemberVipInfoListByVipCode(String vipCode) {
        return memberVipInfoMapper.queryMemberVipInfoListByVipCode(vipCode);
    }

    @Override
    public MemberVipInfoPO queryEffectiveMemberVipInfoByVipType(Integer vipType) {
        if (vipType == null) {
            return null;
        }
        return memberVipInfoMapper.queryEffectiveMemberVipInfoByVipType(vipType, MemberVipStatusEnum.RUNNING.getType());
    }

    @Override
    public List<MemberVipInfoPO> queryMemberVipInfoListByVipType(Integer vipType) {
        return memberVipInfoMapper.queryMemberVipInfoListByVipType(vipType);
    }

    @Override
    public List<MemberVipInfoPO> queryEffectiveMemberVipInfoList() {
        return memberVipInfoMapper.queryEffectiveMemberVipInfoList();
    }
}
